home *** CD-ROM | disk | FTP | other *** search
- /*
- * CBLibrary - Macros
- * Copyright (C) 2003 Chris Bazley
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
- #ifndef CJBMacros_h
- #define CJBMacros_h
-
- #include "kernel.h"
- #include "msgtrans.h"
-
- /* --- Memory --- */
- #define FREE(memptr) {free(memptr);memptr=NULL;}
-
- /* --- Error reporting/checking --- */
- #define THROW(func) {_kernel_oserror *errptr;errptr=func;if(errptr != NULL) return errptr;}
-
- #define WRITE_ERR(block, token) strncpy(block.errmess, msgs_lookup(token), sizeof(block.errmess)-1)
- #define WRITE_GERR(block, token) strncpy(block.errmess, msgs_global(token), sizeof(block.errmess)-1)
-
- #define WRITE_ERR_SUB1(block, token, sub) strncpy(block.errmess, msgs_lookupsub(token, sub, NULL, NULL, NULL), sizeof(block.errmess)-1)
-
- /* --- Useful for sprite widths (inc. RH wastage) --- */
- #define WORD_ALIGN(width) ((((width) + 3) >> 2) << 2)
-
- /* Check for internal error */
- #define E_RET(errblk) { \
- _kernel_oserror *er = errblk; \
- if(er != NULL) { \
- err_check_rep(er); \
- return; \
- } \
- }
-
- #define E_RETV(errblk, value) { \
- _kernel_oserror *er = errblk; \
- if(er != NULL) { \
- err_check_rep(er); \
- return value; \
- } \
- }
-
- /* suppress compiler warnings about unused fn arguments */
- #define NOT_USED(x) {x = x;}
-
- #define SCALE(value, perc) (((value)*(perc))/100)
-
- #define SWAP(a, b) { \
- int temp; \
- temp = a; \
- a = b; \
- b = temp; \
- }
-
-
- /* This comes out really neat in ARM code, honest! */
- #define ABSDIFF(d, x, y) { \
- if(x > y) \
- d = x - y; \
- else \
- d = y - x; \
- }
-
- /* Report internal error */
- #define R(token) err_complain(255,msgs_lookup(token))
- #define R_RET(token) {err_complain(255,msgs_lookup(token));return;}
- #define R_RETV(token, value) {err_complain(255,msgs_lookup(token));return value;}
- #define RG(token) err_complain(255,msgs_global(token))
- #define RG_RET(token) {err_complain(255,msgs_global(token));return;}
- #define RG_RETV(token, value) {err_complain(255,msgs_global(token));return value;}
-
- /* Report non-fatal */
- #define M(token) err_report(255,msgs_lookup(token))
- #define M_RET(token) {err_report(255,msgs_lookup(token));return;}
- #define M_RETV(token, value) {err_report(255,msgs_lookup(token));return value;}
-
- #define MG(token) err_report(255,msgs_global(token))
- #define MG_RET(token) {err_report(255,msgs_global(token));return;}
- #define MG_RETV(token, value) {err_report(255,msgs_global(token));return value;}
-
- /* Bitfields */
- #define FLAG_SET(flags, bit) ((flags & (bit)) != 0)
- #define CLEAR_FLAG(bitfield, bit) bitfield = bitfield & (~(bit))
- #define SET_FLAG(bitfield, bit) bitfield = bitfield | (bit)
-
- /* filetypes */
- #define FILETYPE_DIR 0x1000
- #define FILETYPE_APP 0x2000
- #define FILETYPE_SPRITE 0xff9
- #define FILETYPE_TEXT 0xfff
- #define FILETYPE_DATA 0xffd
- #define FILETYPE_SQUASH 0xfca
-
- #endif
-